/**
 *
 */
package cn.com.generaldata.os.mvc;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cn.com.generaldata.os.constant.ReportConstant;
import cn.com.generaldata.os.newpojo.ReportType;
import cn.com.generaldata.os.pojo.User;
import cn.com.generaldata.os.pojo.mvc.Report;
import cn.com.generaldata.os.pojo.mvc.Row;
import cn.com.generaldata.os.util.XMLComplexityIntf;
import cn.com.generaldata.os.util.XMLUtil;

/**
 * @author Bernd
 * 
 */
public class ReportServletHandler {
	private static Log log = LogFactory.getLog(ReportServletHandler.class);
	private static final String log_header = "[MVC][ReportServletHandler]";

	@SuppressWarnings("unused")
	private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private static SimpleDateFormat sdf_year = new SimpleDateFormat("yyyy");
	private static SimpleDateFormat sdf_month = new SimpleDateFormat("MM");
	private static SimpleDateFormat sdf_day = new SimpleDateFormat("yyyy-MM-dd");

	private static String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
	private static String XSL_HEADER = "<?xml-stylesheet type=\"text/xsl\" href=\"%xsl_name%\"?>\r\n";

	public static Report handleReportRequest(HttpServletRequest request) {
		if (null == request) {
			return null;
		}
		String[] rowId;
		String[] rowType;
		String[] groupNo;
		String[] rowIndex;
		String[] f1;
		String[] f2;
		String[] f3;
		String[] f4;
		String[] f5;
		String[] f6;
		String[] f7;
		String[] f8;
		String[] f9;
		String[] f10;
		String[] f11;
		String[] f12;
		String[] f13;
		String[] f14;
		String[] f15;
		String[] f16;
		String[] f17;
		String[] f18;
		String[] f19;
		String[] f20;
		String[] f21;
		String[] f22;
		String[] f23;
		String[] f24;
		String[] f25;
		String[] f26;
		String[] f27;
		String[] f28;
		String[] f29;
		String[] f30;
		String[] f31;
		String[] f32;
		String[] f33;
		String[] f34;
		String[] f35;
		String[] f36;
		String[] f37;
		String[] f38;
		String[] f39;
		String[] f40;
		String[] f41;
		String[] f42;
		String[] f43;
		String[] f44;
		String[] f45;
		String[] f46;
		String[] f47;
		String[] f48;
		String[] f49;
		String[] f50;
		String[] f51;
		String[] f52;
		String[] f53;
		String[] f54;
		String[] f55;
		String[] f56;
		String[] f57;
		String[] f58;
		String[] f59;
		String[] f60;

		Report report = new Report();

		// fill report rows
		fillReportProperties(request, report);
		rowId = request.getParameterValues("rowId");
		rowType = request.getParameterValues("rowType");
		// groupNo = request.getParameterValues("groupNo");
		rowIndex = request.getParameterValues("rowIndex");
		f1 = request.getParameterValues("f1");
		f2 = request.getParameterValues("f2");
		f3 = request.getParameterValues("f3");
		f4 = request.getParameterValues("f4");
		f5 = request.getParameterValues("f5");
		f6 = request.getParameterValues("f6");
		f7 = request.getParameterValues("f7");
		f8 = request.getParameterValues("f8");
		f9 = request.getParameterValues("f9");
		f10 = request.getParameterValues("f10");
		f11 = request.getParameterValues("f11");
		f12 = request.getParameterValues("f12");
		f13 = request.getParameterValues("f13");
		f14 = request.getParameterValues("f14");
		f15 = request.getParameterValues("f15");
		f16 = request.getParameterValues("f16");
		f17 = request.getParameterValues("f17");
		f18 = request.getParameterValues("f18");
		f19 = request.getParameterValues("f19");
		f20 = request.getParameterValues("f20");
		f21 = request.getParameterValues("f21");
		f22 = request.getParameterValues("f22");
		f23 = request.getParameterValues("f23");
		f24 = request.getParameterValues("f24");
		f25 = request.getParameterValues("f25");
		f26 = request.getParameterValues("f26");
		f27 = request.getParameterValues("f27");
		f28 = request.getParameterValues("f28");
		f29 = request.getParameterValues("f29");
		f30 = request.getParameterValues("f30");
		f31 = request.getParameterValues("f31");
		f32 = request.getParameterValues("f32");
		f33 = request.getParameterValues("f33");
		f34 = request.getParameterValues("f34");
		f35 = request.getParameterValues("f35");
		f36 = request.getParameterValues("f36");
		f37 = request.getParameterValues("f37");
		f38 = request.getParameterValues("f38");
		f39 = request.getParameterValues("f39");
		f40 = request.getParameterValues("f40");
		f41 = request.getParameterValues("f41");
		f42 = request.getParameterValues("f42");
		f43 = request.getParameterValues("f43");
		f44 = request.getParameterValues("f44");
		f45 = request.getParameterValues("f45");
		f46 = request.getParameterValues("f46");
		f47 = request.getParameterValues("f47");
		f48 = request.getParameterValues("f48");
		f49 = request.getParameterValues("f49");
		f50 = request.getParameterValues("f50");
		f51 = request.getParameterValues("f51");
		f52 = request.getParameterValues("f52");
		f53 = request.getParameterValues("f53");
		f54 = request.getParameterValues("f54");
		f55 = request.getParameterValues("f55");
		f56 = request.getParameterValues("f56");
		f57 = request.getParameterValues("f57");
		f58 = request.getParameterValues("f58");
		f59 = request.getParameterValues("f59");
		f60 = request.getParameterValues("f60");

		List<Row> rows = new ArrayList<Row>();
		for (int i = 0, size = rowIndex.length; i < size; i++) {
			Row row = new Row();
			row.setRowId(rowId[i]);
			if (rowType == null || rowType[i] == null) {
				row.setRowType(Row.ROW_TYPE_INPUT);
			} else {
				row.setRowType(Byte.parseByte(rowType[i]));
			}
			// row.setGroupNo(groupNo[i]);
			// null == f1 || f1.length == 0 ? "" : f1[i]
			row.setRowIndex(Integer.valueOf(rowIndex[i]));
			row.setF1(getFileValue(i, f1));
			row.setF2(getFileValue(i, f2));
			row.setF3(getFileValue(i, f3));
			row.setF4(getFileValue(i, f4));
			row.setF5(getFileValue(i, f5));
			row.setF6(getFileValue(i, f6));
			row.setF7(getFileValue(i, f7));
			row.setF8(getFileValue(i, f8));
			row.setF9(getFileValue(i, f9));
			row.setF10(getFileValue(i, f10));
			row.setF11(getFileValue(i, f11));
			row.setF12(getFileValue(i, f12));
			row.setF13(getFileValue(i, f13));
			row.setF14(getFileValue(i, f14));
			row.setF15(getFileValue(i, f15));
			row.setF16(getFileValue(i, f16));
			row.setF17(getFileValue(i, f17));
			row.setF18(getFileValue(i, f18));
			row.setF19(getFileValue(i, f19));
			row.setF20(getFileValue(i, f20));
			row.setF21(getFileValue(i, f21));
			row.setF22(getFileValue(i, f22));
			row.setF23(getFileValue(i, f23));
			row.setF24(getFileValue(i, f24));
			row.setF25(getFileValue(i, f25));
			row.setF26(getFileValue(i, f26));
			row.setF27(getFileValue(i, f27));
			row.setF28(getFileValue(i, f28));
			row.setF29(getFileValue(i, f29));
			row.setF30(getFileValue(i, f30));
			row.setF31(getFileValue(i, f31));
			row.setF32(getFileValue(i, f32));
			row.setF33(getFileValue(i, f33));
			row.setF34(getFileValue(i, f34));
			row.setF35(getFileValue(i, f35));
			row.setF36(getFileValue(i, f36));
			row.setF37(getFileValue(i, f37));
			row.setF38(getFileValue(i, f38));
			row.setF39(getFileValue(i, f39));
			row.setF40(getFileValue(i, f40));
			row.setF41(getFileValue(i, f41));
			row.setF42(getFileValue(i, f42));
			row.setF43(getFileValue(i, f43));
			row.setF44(getFileValue(i, f44));
			row.setF45(getFileValue(i, f45));
			row.setF46(getFileValue(i, f46));
			row.setF47(getFileValue(i, f47));
			row.setF48(getFileValue(i, f48));
			row.setF49(getFileValue(i, f49));
			row.setF50(getFileValue(i, f50));
			row.setF51(getFileValue(i, f51));
			row.setF52(getFileValue(i, f52));
			row.setF53(getFileValue(i, f53));
			row.setF54(getFileValue(i, f54));
			row.setF55(getFileValue(i, f55));
			row.setF56(getFileValue(i, f56));
			row.setF57(getFileValue(i, f57));
			row.setF58(getFileValue(i, f58));
			row.setF59(getFileValue(i, f59));
			row.setF60(getFileValue(i, f60));

			if (null == row.getRowId() || row.getRowId().trim().length() == 0) {
				row.setCreateDate(new Date());
			}
			row.setLastEditDate(new Date());
			rows.add(row);
		}
		report.setRows(rows);
		return report;
	}

	private static String getFileValue(int index, String[] sources) {
		String result = "";
		if (sources != null && sources.length > 0) {
			try {
				result = sources[index];
			} catch (Exception e) {

			}
		}

		return result;
	}

	/**
	 * 
	 * @param user 报表创建人
	 * @param operator 报表最后操作人
	 * @param proxy 报表代填人
	 * @param rType 报表类型
	 * @return 报表xml
	 */
	public static Report generateReportForNew(User user, User operator, User proxy, ReportType rType, String timeType,
			String yearType, String timeDate, String quarterDate, Report lasttimeReport, String reportVersion,
			String unitIndustryId) {

		Validate.notNull(user, "user不能为空");
		Validate.notNull(operator, "operator不能为空");
		Validate.notNull(rType, "rType不能为空");

		String yearValue = "";
		String monthValue = "";
		String quarterValue = "";
		// 获取当前时间的年份
		if (timeType.equals("1")) {
			yearValue = timeDate.substring(0, 4);
			monthValue = timeDate;
		}
		if (timeType.equals("0")) {
			yearValue = timeDate.substring(0, 4);
			monthValue = timeDate;
		}
		if (timeType.equals("2")) {
			yearValue = timeDate.substring(0, 4);
			quarterValue = quarterDate;
		}

		Report report = new Report();

		fillNewReportProperties(report, user, operator, proxy, rType, timeType, yearType, yearValue, monthValue,
				quarterValue, lasttimeReport, reportVersion, unitIndustryId);
		return report;
	}

	public static Report generateReportForUpdate(Report report, User operator) {
		fillUpdateReportProperties(report, operator);

		return report;
	}

	public static Report generateReportForShow(Report report, User operator) {
		fillUpdateReportProperties(report, operator);
		return report;
	}

	public static String generateReportXML(Report report, User operator, String versionV) {
		fillUpdateReportProperties(report, operator);
		String xml = XMLUtil.marshalComplex(report, new XMLComplexityIntf() {

			@SuppressWarnings("rawtypes")
			@Override
			public Map<String, Class> generateAliasMap() {
				Map<String, Class> map = new HashMap<String, Class>();
				map.put("Report", Report.class);
				map.put("Row", Row.class);
				return map;
			}

		});

		return xml;
	}

	private static void fillReportProperties(HttpServletRequest request, Report report) {
		report.setReportType(request.getParameter("reportType"));
		report.setReportTypeCode(request.getParameter("reportTypeCode"));
		report.setReportId(request.getParameter("reportId"));
		report.setReportReferenceId(request.getParameter("reportReferenceId"));
		report.setReportUserId(request.getParameter("reportUserId"));
		report.setReportOperatorId(request.getParameter("reportOperatorId"));
		// 新增代填人id项
		if (request.getParameter("reportProxyId") != "") {
			report.setReportProxyId(request.getParameter("reportProxyId"));
		}

		report.setReportAreaId(request.getParameter("reportAreaId"));
		report.setRegionName(request.getParameter("regionName"));
		report.setRegionOcean(request.getParameter("regionOcean"));
		report.setCityName(request.getParameter("cityName"));
		report.setDepartmentName(request.getParameter("departmentName"));
		report.setRegionCode(request.getParameter("regionCode"));
		report.setReportUnit(request.getParameter("reportUnit"));
		report.setReportUnitIndustry(request.getParameter("reportUnitIndustry"));
		report.setInstitutionName(request.getParameter("institutionName"));
		report.setInstitutionCode(request.getParameter("institutionCode"));
		report.setDomainName(request.getParameter("domainName"));
		report.setDomainCode(request.getParameter("domainCode"));
		String year = request.getParameter("reportYear");
		report.setReportYear(year);
		String quarter = request.getParameter("reportQuarter");
		report.setReportQuarter(quarter);
		report.setReportNo(""); // 统一走报表属性，便于以后的维护
		report.setReportAdmin(""); //
		report.setApproveAdmin(""); //
		report.setApproveNo(""); //
		report.setExpireDate(""); //
		report.setMeasureUnit(""); //
		report.setUnitAdmin(request.getParameter("reportUnitAdmin"));
		report.setStatAdmin(request.getParameter("reportStatAdmin"));
		report.setFillAdmin(request.getParameter("reportFillAdmin"));
		report.setReportDate(request.getParameter("reportDate"));
		report.setReportOrigin(request.getParameter("reportOrigin"));
		report.setReportSupplyOrigin(request.getParameter("reportSupplyOrigin"));
		report.setReportDesc(request.getParameter("reportDesc"));
		report.setReportRemark(request.getParameter("reportRemark"));
		// if(null == report.getReportId() || report.getReportId().trim().length() == 0){
		// report.setCreateDate(new Date());
		// }
		// report.setLastEditDate(new Date());
		report.setCheckStatus(Byte.parseByte(request.getParameter("checkStatus")));
		report.setCheckComment(request.getParameter("checkComment"));
		report.setCheckResult(request.getParameter("checkResult"));
		report.setReportTimetype(request.getParameter("reportTimetype"));
		String month = request.getParameter("reportMonth");
		if (month == null || "".equals(month)) {
			month = new String(year + "/01");
		}
		report.setReportMonth(month);
		report.setReportYearTime(request.getParameter("reportYearTime"));
		report.setReportVersion(request.getParameter("reportVersion"));
		report.setReportUnitIndustryId(request.getParameter("reportUnitIndustryId"));
		report.setReportTypeId(request.getParameter("reportTypeId"));
		report.setReportEdition(request.getParameter("reportEdition"));
		report.setSelfSet1(request.getParameter("selfSet1"));
		report.setSelfSet2(request.getParameter("selfSet2"));
		report.setSelfSet3(request.getParameter("selfSet3"));
		report.setSelfSet4(request.getParameter("selfSet4"));
		report.setSelfSet5(request.getParameter("selfSet5"));
		report.setUnitId(request.getParameter("unitId"));
		// try {
		// report.setCheckSuccessDate(sdf.parse(request.getParameter("checkSuccessDate")));
		// } catch (ParseException ex) {
		// report.setCheckSuccessDate(null);
		// }
	}

	private static String getXSLHeader(String reportTypeCode, String updateFlag) {
		if (null == reportTypeCode || reportTypeCode.trim().length() == 0) {
			log.error(log_header + "[getXSLHeader]reportTypeCode is null");
			return null;
		}

		StringBuffer xslBuffer = new StringBuffer("report_").append(reportTypeCode.toLowerCase()).append(updateFlag)
				.append(".xsl");
		String xslName = XSL_HEADER.replace("%xsl_name%", xslBuffer.toString());

		return xslName;
	}

	private static Report loadReportTemplate(String reportCode, String versionV) {
		if (null == reportCode || reportCode.trim().length() == 0) {
			log.error(log_header + "[loadReportTemplate]reportCode is null");
			return null;
		}

		String templateFile = "reports" + File.separator + "report_" + reportCode.toLowerCase() + "_" + versionV
				+ ".xml";
		Report report = (Report) XMLUtil.loadFromClassPathFile(templateFile, new XMLComplexityIntf() {

			@SuppressWarnings("rawtypes")
			@Override
			public Map<String, Class> generateAliasMap() {
				Map<String, Class> map = new HashMap<String, Class>();
				map.put("Report", Report.class);
				map.put("Row", Row.class);
				return map;
			}
		});

		return report;
	}

	private static String getQuarter(String month) {
		if (null == month || month.trim().length() == 0) {
			log.error(log_header + "[getQuarter]month is null");
			return "";
		}

		if ("01".equals(month) || "02".equals(month) || "03".equals(month)) {
			return "01";
		} else if ("04".equals(month) || "05".equals(month) || "06".equals(month)) {
			return "02";
		} else if ("07".equals(month) || "08".equals(month) || "09".equals(month)) {
			return "03";
		} else if ("10".equals(month) || "11".equals(month) || "12".equals(month)) {
			return "04";
		} else {
			return "";
		}
	}

	private static void fillNewReportProperties(Report report, User user, User operator, User proxy, ReportType rType,
			String timeType, String yearType, String yearValue, String monthValue, String quarterValue,
			Report lasttimeReport, String reportVersion, String unitIndustryId) {

		if (proxy != null) {
			report.setReportProxyId(String.valueOf(proxy.getId()));
		}
		report.setReportId(null);
		report.setReportReferenceId(null);
		report.setUnitId(user.getUserUnit().getId());
		report.setReportUserId(user.getId());
		report.setRegionName(user.getUserRegionName());
		report.setRegionOcean(user.getUserRegionOcean());
		report.setCityName(user.getUserCityName());
		report.setDepartmentName(user.getUserDepartmentName());
		report.setRegionCode(user.getUserRegionCode());
		report.setReportUnit(user.getUserUnit().getUnitName());
		report.setReportUnitIndustryId(unitIndustryId);
		report.setInstitutionName(user.getUserInstitutionName());
		report.setInstitutionCode(user.getUserInstitutionCode());
		report.setDomainName(user.getUserDomainName());
		report.setDomainCode(user.getUserDomainCode());
		report.setReportYear(yearValue);
		report.setReportQuarter(quarterValue);
		report.setUnitAdmin(user.getUserUnitAdmin());
		report.setStatAdmin(user.getUserStatAdmin());
		report.setFillAdmin(user.getUserFillAdmin());
		report.setReportDate(sdf_day.format(new Date()));
		report.setCheckStatus(ReportConstant.FLAG_UNCOMMITTED);
		report.setCheckComment("");
		report.setCheckResult("");
		// report.setCheckSuccessDate(null);
		report.setReportOperatorId(operator.getId());
		// 自加
		report.setReportAreaId(user.getArea().getId());
		// report.setCreateDate(new Date());
		// report.setLastEditDate(new Date());
		report.setReportTimetype(timeType);
		report.setReportVersion(reportVersion);

		Calendar date = Calendar.getInstance();
		int month = date.get(Calendar.MONTH);
		int year = date.get(Calendar.YEAR);
		if (monthValue == null || "".equals(monthValue)) {
			if (month < 9)
				monthValue = year + "/0" + (month + 1);
			else
				monthValue = year + "/" + (month + 1);
		} else {
			String yearParam = monthValue.substring(0, 4);
			year = Integer.valueOf(yearParam);
			String monthParam = monthValue.substring(5, 7);
			month = Integer.valueOf(monthParam) - 1;
		}
		report.setReportMonth(monthValue);
		report.setMonth(month + 1);
		// 当时年报时，获取年报的次数
		if (timeType.equals("1")) {
			if (yearType.equals("1")) { // 半年
				// if (lasttimeReport != null) {
				// if (!yearValue.equals(lasttimeReport.getReportYear())) {
				// report.setReportYearTime("1");
				// } else {
				// report.setReportYearTime("4");
				// }
				// 去年全年报
				//				if (month < 6) {
				//					report.setReportYearTime("2");
				//					report.setReportYear(String.valueOf(Integer.valueOf(yearValue) - 1));
				//				} else {
				report.setReportYearTime("1");
				//				}
			} else if (yearType.equals("2")) { // 全年报
				report.setReportYearTime("2");
			}
		}

		report.setReportType(rType.getTypeName());
		report.setReportTypeCode(rType.getTypeCode());
		report.setReportNo(rType.getTypeNo());
		report.setReportAdmin(rType.getTypeReportAdmin().toString());
		report.setApproveAdmin(rType.getTypeApproveAdmin().toString());
		report.setApproveNo(rType.getTypeApproveNo());
		report.setExpireDate(rType.getTypeExpireDate());
		report.setMeasureUnit(rType.getTypeMeasureUnit());
		report.setReportTypeId(rType.getId());

		// // 获取上次记录（环比），上级记录不为空并且可以获取上次记录
		// if (lasttimeReport != null && rType.getTypeLastTime() != 0) {
		// if (lasttimeReport.getRows().size() > 0) {
		// List<Row> rows = new ArrayList<Row>();
		// int i = 0;
		// for (Row r : report.getRows()) {
		// // r.setCreateDate(new Date());
		// // r.setLastEditDate(new Date());
		// r.setF1(lasttimeReport.getRows().get(i).getF1());
		// r.setF2(lasttimeReport.getRows().get(i).getF2());
		// r.setF3(lasttimeReport.getRows().get(i).getF3());
		// r.setF4(lasttimeReport.getRows().get(i).getF4());
		// r.setF5(lasttimeReport.getRows().get(i).getF5());
		// r.setF6(lasttimeReport.getRows().get(i).getF6());
		// r.setF7(lasttimeReport.getRows().get(i).getF7());
		// r.setF8(lasttimeReport.getRows().get(i).getF8());
		// r.setF9(lasttimeReport.getRows().get(i).getF9());
		// r.setF10(lasttimeReport.getRows().get(i).getF10());
		// r.setF11(lasttimeReport.getRows().get(i).getF11());
		// r.setF12(lasttimeReport.getRows().get(i).getF12());
		// r.setF13(lasttimeReport.getRows().get(i).getF13());
		// r.setF14(lasttimeReport.getRows().get(i).getF14());
		// r.setF15(lasttimeReport.getRows().get(i).getF15());
		// r.setF16(lasttimeReport.getRows().get(i).getF16());
		// r.setF17(lasttimeReport.getRows().get(i).getF17());
		// r.setF18(lasttimeReport.getRows().get(i).getF18());
		// r.setF19(lasttimeReport.getRows().get(i).getF19());
		// r.setF20(lasttimeReport.getRows().get(i).getF20());
		// r.setF21(lasttimeReport.getRows().get(i).getF21());
		// r.setF22(lasttimeReport.getRows().get(i).getF22());
		// r.setF23(lasttimeReport.getRows().get(i).getF23());
		// r.setF24(lasttimeReport.getRows().get(i).getF24());
		// r.setF25(lasttimeReport.getRows().get(i).getF25());
		// r.setF26(lasttimeReport.getRows().get(i).getF26());
		// r.setF27(lasttimeReport.getRows().get(i).getF27());
		// r.setF28(lasttimeReport.getRows().get(i).getF28());
		// r.setF29(lasttimeReport.getRows().get(i).getF29());
		// r.setF30(lasttimeReport.getRows().get(i).getF30());
		// r.setF31(lasttimeReport.getRows().get(i).getF31());
		// r.setF32(lasttimeReport.getRows().get(i).getF32());
		// r.setF33(lasttimeReport.getRows().get(i).getF33());
		// r.setF34(lasttimeReport.getRows().get(i).getF34());
		// r.setF35(lasttimeReport.getRows().get(i).getF35());
		// r.setF36(lasttimeReport.getRows().get(i).getF36());
		// r.setF37(lasttimeReport.getRows().get(i).getF37());
		// r.setF38(lasttimeReport.getRows().get(i).getF38());
		// r.setF39(lasttimeReport.getRows().get(i).getF39());
		// r.setF40(lasttimeReport.getRows().get(i).getF40());
		// r.setF41(lasttimeReport.getRows().get(i).getF41());
		// r.setF42(lasttimeReport.getRows().get(i).getF42());
		// r.setF43(lasttimeReport.getRows().get(i).getF43());
		// r.setF44(lasttimeReport.getRows().get(i).getF44());
		// r.setF45(lasttimeReport.getRows().get(i).getF45());
		// r.setF46(lasttimeReport.getRows().get(i).getF46());
		// r.setF47(lasttimeReport.getRows().get(i).getF47());
		// r.setF48(lasttimeReport.getRows().get(i).getF48());
		// r.setF49(lasttimeReport.getRows().get(i).getF49());
		// r.setF50(lasttimeReport.getRows().get(i).getF50());
		// r.setF51(lasttimeReport.getRows().get(i).getF51());
		// r.setF52(lasttimeReport.getRows().get(i).getF52());
		// r.setF53(lasttimeReport.getRows().get(i).getF53());
		// r.setF54(lasttimeReport.getRows().get(i).getF54());
		// r.setF55(lasttimeReport.getRows().get(i).getF55());
		// r.setF56(lasttimeReport.getRows().get(i).getF56());
		// r.setF57(lasttimeReport.getRows().get(i).getF57());
		// r.setF58(lasttimeReport.getRows().get(i).getF58());
		// r.setF59(lasttimeReport.getRows().get(i).getF59());
		// r.setF60(lasttimeReport.getRows().get(i).getF60());
		//
		// i++;
		// rows.add(r);
		// }
		// report.setRows(rows);
		// }
		// }
	}

	private static void fillUpdateReportProperties(Report report, User operator) {
		// report.setLastEditDate(new Date());
		if (report == null) {
			report = new Report();
		}
		report.setReportOperatorId(String.valueOf(operator.getId()));
		if (report.getReportUnitIndustry() == null || StringUtils.isBlank(report.getReportUnitIndustry())) {
			report.setReportUnitIndustry("");
		}
		if (report.getReportReferenceId() == null || StringUtils.isBlank(report.getReportReferenceId())) {
			report.setReportReferenceId("");
		}
	}

}
